package com.yunze.quartz.task.yunze.test;

import com.alibaba.fastjson.JSON;
import com.yunze.apiCommon.utils.VeDate;
import com.yunze.common.mapper.mysql.YrootlowHisMapper;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Component("tdTestTask")
public class TdTestTask {

    @Resource
    private RabbitTemplate rabbitTemplate;




    public void Test(){
        //1.创建路由 绑定 生产队列 发送消息
        //导卡 路由队列
        String polling_queueName = "admin_TdTest_queue";
        String polling_routingKey = "admin.TdTest.queue";
        String polling_exchangeName = "admin_exchange";//路由

        try {
            Map<String, Object> start_Map = new HashMap<>();
            rabbitTemplate.convertAndSend(polling_exchangeName, polling_routingKey, JSON.toJSONString(start_Map), message -> {
                // 设置消息过期时间 30 分钟 过期
                message.getMessageProperties().setExpiration("" + (30 * 1000 * 60));
                return message;
            });
        } catch (Exception e) {
            System.out.println(" TdTestTask 指令发送失败 " + e.getMessage());
        }

    }


    /**
     * 迁移 yz_card_flow_his 至 TDengine
     * @param create_time
     * @param type
     * @param staTime
     * @param endTime
     */
    public void migrateCardFlowHis(String create_time,String type,String staTime,String endTime) {
        String polling_queueName = "admin_migrateCardFlowHis_queue";
        String polling_routingKey = "admin.migrateCardFlowHis.queue";
        String polling_exchangeName = "admin_exchange";//路由

        try {
            create_time = create_time.length()>0?create_time:null;
            type = type.length()>0?type:null;
            staTime = staTime.length()>0?staTime:null;
            endTime = endTime.length()>0?endTime:null;
            Map<String, Object> start_Map = new HashMap<>();
            start_Map.put("type",type);
            start_Map.put("create_time",create_time);
            start_Map.put("staTime",staTime);
            start_Map.put("endTime",endTime);
            rabbitTemplate.convertAndSend(polling_exchangeName, polling_routingKey, JSON.toJSONString(start_Map), message -> {
                // 设置消息过期时间 30 分钟 过期
                message.getMessageProperties().setExpiration("" + (30 * 1000 * 60));
                return message;
            });
        } catch (Exception e) {
            System.out.println(" migrateCardFlowHis 指令发送失败 " + e.getMessage());
        }
    }


}
